﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Database;
using DB;
using BL;

namespace UI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
			AccessDb.Instance.FileName = @"../DB/db1.mdb";
			AccessDb.Instance.OpenConnection();
			TableItemMapper tiMapper = new TableItemMapper();
			SubjectItemMapper siMapper = new SubjectItemMapper();
            TopicMapper tMapper = new TopicMapper();
            NagruzkaMapper nMapper = new NagruzkaMapper();
            List<JurnalItem> itemList = new List<JurnalItem>();
			new Subjects(siMapper.LoadAll());
            new Topiki(tMapper.LoadAll());
			new Table(tiMapper.LoadAll());
            new Nagruzki(nMapper.LoadAll());
            for (int i = 0; i < Nagruzki.Instance.Items.Length; i++)
            {
                JurnalItem item = new JurnalItem();
                item.Id = Nagruzki.Instance.Items[i].ID.ToString();
                item.SubjectItem = Nagruzki.Instance.Items[i].SubjectItem.Subject;
                item.Chislo = Nagruzki.Instance.Items[i].Chislo;
                item.Group = Nagruzki.Instance.Items[i].SubjectItem.Group;
                item.Theme = Nagruzki.Instance.Items[i].Theme;
                item.Faculty = Nagruzki.Instance.Items[i].SubjectItem.Faculty;
                if (Nagruzki.Instance.Items[i].SubjectItem.LessonType == LessonTypes.Дипломное||Nagruzki.Instance.Items[i].SubjectItem.LessonType == LessonTypes.Курсовое)
                    item.Prochee = Nagruzki.Instance.Items[i].Hour.ToString();                
                if (Nagruzki.Instance.Items[i].SubjectItem.LessonType == LessonTypes.Лекции)
                    item.Lecture = Nagruzki.Instance.Items[i].Hour.ToString();
                if (Nagruzki.Instance.Items[i].SubjectItem.LessonType == LessonTypes.Практика)
                    item.Practika = Nagruzki.Instance.Items[i].Hour.ToString();
                itemList.Add(item);
            }
            new Jurnaly(itemList);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());

			AccessDb.Instance.Commit();
			AccessDb.Instance.CloseConnection();
        }
    }
}